﻿// MedicalRulesEngine.Core/Services/IMetadataService.cs
using MedicalRulesEngine.Core.DTOs;

namespace MedicalRulesEngine.Core.Services;

/// <summary>
/// 元数据服务接口
/// 提供字段定义、操作符定义等元数据管理功能
/// </summary>
public interface IMetadataService
{
    /// <summary>
    /// 获取所有字段定义
    /// </summary>
    /// <returns>字段定义集合</returns>
    Task<IEnumerable<FieldDefinitionDto>> GetAllFieldDefinitionsAsync();

    /// <summary>
    /// 根据分类获取字段定义
    /// </summary>
    /// <param name="category">分类</param>
    /// <returns>字段定义集合</returns>
    Task<IEnumerable<FieldDefinitionDto>> GetFieldDefinitionsByCategoryAsync(string category);

    /// <summary>
    /// 获取所有操作符定义
    /// </summary>
    /// <returns>操作符定义集合</returns>
    Task<IEnumerable<OperatorDefinitionDto>> GetAllOperatorDefinitionsAsync();

    /// <summary>
    /// 根据数据类型获取支持的操作符
    /// </summary>
    /// <param name="dataType">数据类型</param>
    /// <returns>操作符定义集合</returns>
    Task<IEnumerable<OperatorDefinitionDto>> GetOperatorsByDataTypeAsync(string dataType);

    /// <summary>
    /// 获取规则编辑器配置
    /// </summary>
    /// <returns>编辑器配置</returns>
    Task<RuleEditorConfig> GetRuleEditorConfigAsync();

    /// <summary>
    /// 初始化默认元数据
    /// </summary>
    Task InitializeDefaultMetadataAsync();
}

/// <summary>
/// 规则编辑器配置
/// </summary>
public class RuleEditorConfig
{
    /// <summary>
    /// 字段定义集合
    /// </summary>
    public List<FieldDefinitionDto> FieldDefinitions { get; set; } = new();

    /// <summary>
    /// 操作符定义集合
    /// </summary>
    public List<OperatorDefinitionDto> OperatorDefinitions { get; set; } = new();

    /// <summary>
    /// 数据类型定义
    /// </summary>
    public List<DataTypeDefinition> DataTypes { get; set; } = new();

    /// <summary>
    /// 动作类型定义
    /// </summary>
    public List<ActionTypeDefinition> ActionTypes { get; set; } = new();

    /// <summary>
    /// 优先级定义
    /// </summary>
    public List<PriorityDefinition> Priorities { get; set; } = new();

    /// <summary>
    /// 分类定义
    /// </summary>
    public List<CategoryDefinition> Categories { get; set; } = new();
}

/// <summary>
/// 数据类型定义
/// </summary>
public class DataTypeDefinition
{
    /// <summary>
    /// 类型代码
    /// </summary>
    public string Code { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 默认值
    /// </summary>
    public object? DefaultValue { get; set; }

    /// <summary>
    /// 验证规则
    /// </summary>
    public object? ValidationRules { get; set; }
}

/// <summary>
/// 动作类型定义
/// </summary>
public class ActionTypeDefinition
{
    /// <summary>
    /// 类型代码
    /// </summary>
    public string Code { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 描述
    /// </summary>
    public string? Description { get; set; }

    /// <summary>
    /// 图标
    /// </summary>
    public string? Icon { get; set; }

    /// <summary>
    /// 配置模板
    /// </summary>
    public object? ConfigTemplate { get; set; }
}

/// <summary>
/// 优先级定义
/// </summary>
public class PriorityDefinition
{
    /// <summary>
    /// 优先级值
    /// </summary>
    public int Value { get; set; }

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 颜色
    /// </summary>
    public string Color { get; set; } = string.Empty;

    /// <summary>
    /// 描述
    /// </summary>
    public string? Description { get; set; }
}

/// <summary>
/// 分类定义
/// </summary>
public class CategoryDefinition
{
    /// <summary>
    /// 分类代码
    /// </summary>
    public string Code { get; set; } = string.Empty;

    /// <summary>
    /// 显示名称
    /// </summary>
    public string DisplayName { get; set; } = string.Empty;

    /// <summary>
    /// 图标
    /// </summary>
    public string? Icon { get; set; }

    /// <summary>
    /// 颜色
    /// </summary>
    public string? Color { get; set; }

    /// <summary>
    /// 子分类
    /// </summary>
    public List<CategoryDefinition> SubCategories { get; set; } = new();
}


